﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Parsers.SpeechSynthesizer
{
    public class SyllablesParser
    {
        #region Vars

        private List<string> _syllablesLst;

        private string[] _vowels = new string[] { "а", "о", "у", "ы", "э" };
        private string[] _softsingl = new string[] {"я", "е", "і", "ю", "ё"};
        private string[] _mznak = new string[] { "ь" };
        private string[] _twinsingl = new string[] {"дз", "дж"};

        #endregion

        #region Constructors

        public SyllablesParser(List<string> lettersLst)
        {
            Letters = lettersLst;
            _syllablesLst = new List<string>();
        }

        public SyllablesParser()
        {
            _syllablesLst = new List<string>();
        }

        #endregion

        #region Properties

        public List<string> Syllables
        {
            get { return _syllablesLst;}
        }

        public List<string> Letters { get; set; }

        #endregion
        
        #region Public Methods

        public void Parse()
        {
            for(int i=0; i<Letters.Count; i++)
            {
                
                if (_vowels.Contains(Letters[i]))
                {
                    _syllablesLst.Add(Letters[i]);
                }
                else
                {
                    if (i + 1 >= Letters.Count)
                    {
                        _syllablesLst.Add(Letters[i]);
                    }
                    else
                    {
                        if (_vowels.Contains(Letters[i + 1]))
                        {
                            string _syllable;
                            _syllable = Letters[i] + Letters[i + 1];
                            _syllablesLst.Add(_syllable);
                            i++;
                        }
                        else
                        {
                            if (_softsingl.Contains(Letters[i + 1]) && Letters[i] != "_")
                            {
                                string _syllable;
                                _syllable = Letters[i] + "'" + Letters[i + 1];
                                _syllablesLst.Add(_syllable);
                                i++;
                            }
                            else
                            {
                                string _syllable;
                                if (_mznak.Contains(Letters[i + 1]))
                                {
                                    _syllable = Letters[i] + "'";
                                    _syllablesLst.Add(_syllable);
                                    i++;
                                }
                                else
                                {
                                    string letter = Letters[i] + Letters[i + 1];
                                    if (_twinsingl.Contains(letter))
                                    {
                                        _syllablesLst.Add(letter);
                                        i++;
                                    }
                                    else
                                    {
                                        _syllablesLst.Add(Letters[i]);
                                    }
                                }
                            }
                        }
                    }

                }

                
            }

        }

        #endregion

    }
}
